package myta.bean;

import javax.faces.component.html.HtmlDataTable;

import myta.base.FormBase;
import myta.model.DataRow;
import myta.model.DataTable;
import myta.service.Command;
import myta.service.SQLexec;

public class Jadwal extends FormBase{
	private HtmlDataTable htmldatatable;
	private DataTable datatable;
	private DataTable datatable2;
	private DataTable datatable3;

	@Override
	public void init() throws Exception {
		formName = "jadwal";
		
		htmldatatable = new HtmlDataTable();
		datatable = new DataTable();
		datatable2 = new DataTable();
		datatable3 = new DataTable();
	}
	
	@Override
	public void hapus() throws Exception {
		int selectedRow = htmldatatable.getRowIndex();
		DataRow datarow = datatable.getRow(selectedRow);
		String idjadwal = datarow.getString("idjadwal");
		
		String sql = "delete from jadwal where idjadwal = ?";
		Command command = SQLexec.makeCommand(sql);
		command.setObject(1, idjadwal);
		command.executeUpdate();
	}

	@Override
	public void tampil() throws Exception {
		String sql = "select j.idjadwal,concat(k.namakelas,' ~ ',s.thnajaran) as namakelas, m.namamapel, g.nama, j.hari from jadwal j inner join kelassiswa ks on j.idkelassiswa = ks.idkelassiswa inner join kelas k on ks.idkelas = k.idkelas ";
		sql += "inner join mapel m on j.idmapel = m.idmapel inner join guru g on j.idguru = g.idguru inner join semester s on k.idsemester = s.idsemester where k.namakelas like '%1%'";
		Command command = SQLexec.makeCommand(sql);
		datatable = command.executeQuery();
		
		sql = "select j.idjadwal,concat(k.namakelas,' ~ ',s.thnajaran) as namakelas, m.namamapel, g.nama, j.hari from jadwal j inner join kelassiswa ks on j.idkelassiswa = ks.idkelassiswa inner join kelas k on ks.idkelas = k.idkelas ";
		sql += "inner join mapel m on j.idmapel = m.idmapel inner join guru g on j.idguru = g.idguru inner join semester s on k.idsemester = s.idsemester where k.namakelas like '%2%'";
		command = SQLexec.makeCommand(sql);
		datatable2 = command.executeQuery();
		
		sql = "select j.idjadwal,concat(k.namakelas,' ~ ',s.thnajaran) as namakelas, m.namamapel, g.nama, j.hari from jadwal j inner join kelassiswa ks on j.idkelassiswa = ks.idkelassiswa inner join kelas k on ks.idkelas = k.idkelas ";
		sql += "inner join mapel m on j.idmapel = m.idmapel inner join guru g on j.idguru = g.idguru inner join semester s on k.idsemester = s.idsemester where k.namakelas like '%3%'";
		command = SQLexec.makeCommand(sql);
		datatable3 = command.executeQuery();
	}

	public HtmlDataTable getHtmldatatable() {
		return htmldatatable;
	}

	public void setHtmldatatable(HtmlDataTable htmldatatable) {
		this.htmldatatable = htmldatatable;
	}

	public DataTable getDatatable() {
		return datatable;
	}

	public void setDatatable(DataTable datatable) {
		this.datatable = datatable;
	}

	public DataTable getDatatable2() {
		return datatable2;
	}

	public void setDatatable2(DataTable datatable2) {
		this.datatable2 = datatable2;
	}

	public DataTable getDatatable3() {
		return datatable3;
	}

	public void setDatatable3(DataTable datatable3) {
		this.datatable3 = datatable3;
	}
}
